package com.shf.dynamodb.util;

import com.amazonaws.ClientConfiguration;
import com.amazonaws.client.builder.AwsClientBuilder;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder;

/**
 * 获取客户端公共类
 * @author songhaifeng
 *
 */
public class DynamoDBClientUtil {

	/**
	 * dynamodb连接客户端
	 * @return
	 */
	public static AmazonDynamoDBClient getDynamoclient(){
		AmazonDynamoDBClientBuilder builder = AmazonDynamoDBClientBuilder.standard();
		AmazonDynamoDBClient client = (AmazonDynamoDBClient) builder.withEndpointConfiguration(
                new AwsClientBuilder.EndpointConfiguration("http://localhost:8765", "us-west-2"))
                .build();
		return client;
	}
	
	/**
	 * 指定重试机制的客户端
	 * @return
	 */
	public static AmazonDynamoDBClient getDynamoclientWithRetry(){
		AmazonDynamoDBClientBuilder builder = AmazonDynamoDBClientBuilder.standard();
		ClientConfiguration  clientConfiguration = new ClientConfiguration ();
		clientConfiguration.setMaxErrorRetry(2);
		AmazonDynamoDBClient client = (AmazonDynamoDBClient) builder.withEndpointConfiguration(
                new AwsClientBuilder.EndpointConfiguration("http://localhost:8765", "us-west-2")).withClientConfiguration(clientConfiguration)
                .build();
		return client;
	}
}
